package com.example.qianjun.ninetable;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class PracticeActivity extends AppCompatActivity implements View.OnClickListener {

    private Button clockwise1;
    private Button clockwise2;
    private Button clockwise3;
    private Button clockwise4;
    private Button counterclockwise1;
    private Button counterclockwise2;
    private Button counterclockwise3;
    private Button counterclockwise4;
    private NineTable nineTable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        CheckBoard.init();

        setContentView(R.layout.activity_practice);

        findViews();
        listenerInit();
    }

    public void findViews() {
        clockwise1 = (Button) findViewById(R.id.clockwiseFirst);
        clockwise2 = (Button) findViewById(R.id.clockwiseSecond);
        clockwise3 = (Button) findViewById(R.id.clockwiseThird);
        clockwise4 = (Button) findViewById(R.id.clockwiseFourth);
        counterclockwise1 = (Button) findViewById(R.id.counterclockwiseFirst);
        counterclockwise2 = (Button) findViewById(R.id.counterclockwiseSecond);
        counterclockwise3 = (Button) findViewById(R.id.counterclockwiseThird);
        counterclockwise4 = (Button) findViewById(R.id.counterclockwiseFourth);
        nineTable = (NineTable) findViewById(R.id.ninetable);

    }

    public void listenerInit() {
        clockwise1.setOnClickListener(this);
        clockwise2.setOnClickListener(this);
        clockwise3.setOnClickListener(this);
        clockwise4.setOnClickListener(this);
        counterclockwise1.setOnClickListener(this);
        counterclockwise2.setOnClickListener(this);
        counterclockwise3.setOnClickListener(this);
        counterclockwise4.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.clockwiseFirst:
                GlobalUtil.rotateClockwiseFirst(CheckBoard.practiceTable);
                break;
            case R.id.clockwiseSecond:
                GlobalUtil.rotateClockwiseSecond(CheckBoard.practiceTable);
                break;
            case R.id.clockwiseThird:
                GlobalUtil.rotateClockwiseThird(CheckBoard.practiceTable);
                break;
            case R.id.clockwiseFourth:
                GlobalUtil.rotateClockwiseFourth(CheckBoard.practiceTable);
                break;
            case R.id.counterclockwiseFirst:
                GlobalUtil.rotateCountclockwiseFirst(CheckBoard.practiceTable);
                break;
            case R.id.counterclockwiseSecond:
                GlobalUtil.rotateCountclockwiseSecond(CheckBoard.practiceTable);
                break;
            case R.id.counterclockwiseThird:
                GlobalUtil.rotateCountclockwiseThird(CheckBoard.practiceTable);
                break;
            case R.id.counterclockwiseFourth:
                GlobalUtil.rotateCountclockwiseFourth(CheckBoard.practiceTable);
                break;
        }

        CheckBoard.practiceToShow();
        nineTable.postInvalidate();
    }
}
